<?php

function getTimeToPerformTask($task) {
	$sql = "SELECT day, time FROM timetoperformtask where done = 0 and task = '$task' order by orderVal;";
	
	$timeToPerformTask = null;
	$result = mysql_query($sql);
	
	$row = mysql_fetch_array($result);
	if ($row != null) {
		$timeToPerformTask = new TimeToPerformTask();
		$timeToPerformTask->day = $row['day'];
		$time = preg_split("%:%", $row['time']);
		$timeToPerformTask->hours = $time[0]; 
		$timeToPerformTask->minutes = $time[1];
	}

	return $timeToPerformTask;
}

function updateTimeToPerformTask($task) {
	$sql = "SELECT id FROM timetoperformtask where done = 0 and task = '$task' order by orderVal;";
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
	
	$sql = "UPDATE timetoperformtask set done = 1 where id = " . $row['id'];
	mysql_query($sql);	
}

?>